package com.kele.order.controller;

import com.kele.common.model.response.PageResult;
import com.kele.common.model.response.ResultObject;
import com.kele.model.order.Order;
import com.kele.model.order.OrderItem;
import com.kele.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    HttpServletRequest request;

    @Autowired
    OrderService orderService;
    @PostMapping("create")
    public ResultObject<Map<String, String>> order(@RequestBody List<OrderItem> orderItemList){

        //从Authorization 头信息里面获取 Bearer token
        String userid = request.getHeader("userid_1905A");
        System.out.println("userid=" + userid);
        return orderService.order(userid,orderItemList);
    }

    @PostMapping("findPage/{pageNo}/{pageSize}")
    public PageResult<Order> findPage(@PathVariable Integer pageNo,
                                      @PathVariable Integer pageSize,
                                      @RequestBody Map serachMap){
        //从Authorization 头信息里面获取 Bearer token
        String userid = request.getHeader("userid_1905A");
        System.out.println("userid=" + userid);
        return orderService.findPage(userid,pageNo,pageSize,serachMap);
    }


}
